<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="接上登录的示例代码，接着往下看后台管理页面的实现">
<meta property="og:type" content="article">
<meta property="og:title" content="springboot 二次开发blog（二）">
<meta property="og:url" content="http://example.com/2021/03/16/springboot-%E4%BA%8C%E6%AC%A1%E5%BC%80%E5%8F%91blog%EF%BC%88%E4%BA%8C%EF%BC%89/index.html">
<meta property="og:site_name" content="yyc&#39;s blog">
<meta property="og:description" content="接上登录的示例代码，接着往下看后台管理页面的实现">
<meta property="og:locale">
<meta property="og:image" content="https://gitee.com/goatyyc/giteep-page-imgs/raw/master/imgs/20210316163544.png">
<meta property="article:published_time" content="2021-03-16T08:34:59.000Z">
<meta property="article:modified_time" content="2021-03-16T08:36:51.469Z">
<meta property="article:author" content="yyc">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/goatyyc/giteep-page-imgs/raw/master/imgs/20210316163544.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://example.com/2021/03/16/springboot-二次开发blog（二）/"/>





  <title>springboot 二次开发blog（二） | yyc's blog</title>
  








<meta name="generator" content="Hexo 5.3.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta custom-logo">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">yyc's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术博客</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/03/16/springboot-%E4%BA%8C%E6%AC%A1%E5%BC%80%E5%8F%91blog%EF%BC%88%E4%BA%8C%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yyc's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">springboot 二次开发blog（二）</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2021-03-16T16:34:59+08:00">
                2021-03-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/springboot/" itemprop="url" rel="index">
                    <span itemprop="name">springboot</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>接上登录的示例代码，接着往下看后台管理页面的实现</p>
</blockquote>
<a id="more"></a>

<p>登录成功后：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">return</span> APIResponse.success();</span><br></pre></td></tr></table></figure>


<p>云里雾里看了挺久，思考这个return 返回的是什么，才发现返回的是封装好的“请求成功”格式，再debug中的日志信息可以看到整个生命周期的运行状态。这个得仔细研究一下，方便后续写代码用来debug</p>
<blockquote>
<p>// 研究日志记录</p>
<p>先略过</p>
</blockquote>
<p>回到templates下的前端页面才发现：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&lt;script type=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><br><span class="line">    <span class="comment">/*&lt;![CDATA[*/</span></span><br><span class="line">    <span class="keyword">var</span> tale = <span class="keyword">new</span> $.tale();</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">checkForm</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        tale.post(&#123;</span><br><span class="line">            url: <span class="string">&#x27;/admin/login&#x27;</span>,</span><br><span class="line">            data: $(<span class="string">&quot;#loginForm&quot;</span>).serialize(),</span><br><span class="line">            success: <span class="function"><span class="keyword">function</span> (<span class="params">result</span>) </span>&#123;</span><br><span class="line">                <span class="keyword">if</span> (result &amp;&amp; result.code == <span class="string">&#x27;success&#x27;</span>) &#123;</span><br><span class="line">                    <span class="built_in">window</span>.location.href = <span class="string">&#x27;/admin/index&#x27;</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    tale.alertError(result.msg || <span class="string">&#x27;登录失败&#x27;</span>);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/*]]&gt;*/</span></span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<p>这里是用ajax请求，得到”success”响应后，跳转到 ‘/admin/index’ 下</p>
<h2 id="一、后台主页"><a href="#一、后台主页" class="headerlink" title="一、后台主页"></a>一、后台主页</h2><p>接下来就可以看看 <code>/admin/index</code> 的业务逻辑实现</p>
<p><img src="https://gitee.com/goatyyc/giteep-page-imgs/raw/master/imgs/20210316163544.png" alt="image-20210316160309946"></p>
<h3 id="1、IndexController"><a href="#1、IndexController" class="headerlink" title="1、IndexController"></a>1、IndexController</h3><p>找到首页控制器：IndexController</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">   <span class="comment">// /admin/index </span></span><br><span class="line"></span><br><span class="line"><span class="meta">@ApiOperation(&quot;进入首页&quot;)</span></span><br><span class="line">   <span class="meta">@GetMapping(value = &#123;&quot;&quot;,&quot;/index&quot;&#125;)</span></span><br><span class="line">   <span class="function"><span class="keyword">public</span> String <span class="title">index</span><span class="params">(HttpServletRequest request)</span></span>&#123;</span><br><span class="line">       LOGGER.info(<span class="string">&quot;Enter admin index method&quot;</span>);	<span class="comment">// 打印日志信息</span></span><br><span class="line">       List&lt;CommentDomain&gt; comments = siteService.getComments(<span class="number">5</span>);	<span class="comment">// 获取评论信息</span></span><br><span class="line">       List&lt;ContentDomain&gt; contents = siteService.getNewArticles(<span class="number">5</span>);	<span class="comment">//获取文章信息</span></span><br><span class="line">       StatisticsDto statistics = siteService.getStatistics();	</span><br><span class="line">       <span class="comment">// 取最新的20条日志</span></span><br><span class="line">       PageInfo&lt;LogDomain&gt; logs = logService.getLogs(<span class="number">1</span>, <span class="number">5</span>);		<span class="comment">// 获取日志信息</span></span><br><span class="line">       List&lt;LogDomain&gt; list = logs.getList();</span><br><span class="line">       request.setAttribute(<span class="string">&quot;comments&quot;</span>, comments);</span><br><span class="line">       request.setAttribute(<span class="string">&quot;articles&quot;</span>, contents);</span><br><span class="line">       request.setAttribute(<span class="string">&quot;statistics&quot;</span>, statistics);</span><br><span class="line">       request.setAttribute(<span class="string">&quot;logs&quot;</span>, list);</span><br><span class="line">       LOGGER.info(<span class="string">&quot;Exit admin index method&quot;</span>);</span><br><span class="line">       <span class="keyword">return</span> <span class="string">&quot;admin/index&quot;</span>;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>


<p>看到这里写的很清晰，一眼就能看清楚控制器的任务：</p>
<p>调用service层获取后台首页的相关信息，并设置到request中，以便前端渲染使用</p>
<h3 id="2、service层"><a href="#2、service层" class="headerlink" title="2、service层"></a>2、service层</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">List&lt;CommentDomain&gt; comments = siteService.getComments(<span class="number">5</span>);</span><br><span class="line">List&lt;ContentDomain&gt; contents = siteService.getNewArticles(<span class="number">5</span>);</span><br><span class="line">StatisticsDto statistics = siteService.getStatistics();</span><br><span class="line"><span class="comment">// 取最新的20条日志</span></span><br><span class="line">PageInfo&lt;LogDomain&gt; logs = logService.getLogs(<span class="number">1</span>, <span class="number">5</span>);</span><br></pre></td></tr></table></figure>


<p>先看 siteService.getComments(5);</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">   <span class="comment">// 传入分页参数</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line">   <span class="meta">@Cacheable(value = &quot;siteCache&quot;, key = &quot;&#x27;comments_&#x27; + #p0&quot;)</span></span><br><span class="line">   <span class="function"><span class="keyword">public</span> List&lt;CommentDomain&gt; <span class="title">getComments</span><span class="params">(<span class="keyword">int</span> limit)</span> </span>&#123;</span><br><span class="line">       LOGGER.debug(<span class="string">&quot;Enter recentComments method:limit=&#123;&#125;&quot;</span>, limit);</span><br><span class="line">       <span class="keyword">if</span> (limit &lt; <span class="number">0</span> || limit &gt; <span class="number">10</span>)&#123;</span><br><span class="line">           limit = <span class="number">10</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       PageHelper.startPage(<span class="number">1</span>, limit);		<span class="comment">// 分页插件存储首页</span></span><br><span class="line">       <span class="comment">// dao层调用sql获取评论 ： &lt;!-- 根据条件查找评论列表 --&gt;</span></span><br><span class="line">       List&lt;CommentDomain&gt; rs = commentDao.getCommentsByCond(<span class="keyword">new</span> CommentCond());</span><br><span class="line">       LOGGER.debug(<span class="string">&quot;Exit recentComments method&quot;</span>);</span><br><span class="line">       <span class="keyword">return</span> rs;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<p>其他三个类似</p>
<p>目前通过这种方式就可以解读整个项目，因为时间有限，二开计划暂停。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2021/03/15/springboot%20%E6%A1%88%E4%BE%8B%E5%AD%A6%E4%B9%A0/" rel="next" title="springboot">
                <i class="fa fa-chevron-left"></i> springboot
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2021/03/17/python%E7%88%AC%E8%99%AB%EF%BC%9A%E9%AB%98%E6%95%88%E7%8E%87/" rel="prev" title="pythond爬虫：高效率">
                pythond爬虫：高效率 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.png"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
                <a href="/archives">
                  <span class="site-state-item-count">23</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">9</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%90%8E%E5%8F%B0%E4%B8%BB%E9%A1%B5"><span class="nav-text">一、后台主页</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1%E3%80%81IndexController"><span class="nav-text">1、IndexController</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2%E3%80%81service%E5%B1%82"><span class="nav-text">2、service层</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yyc</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
